**************************************************
/*	Purpose: Annual Statistics Analysis of CAFC decisions	*/
/*	Author: Jason Rantanen	*/
/*	Date Created: January 10, 2022	*/
**************************************************

/* Input Files:
appeals 2021-12-31.dta
2021-12-31 CAFC Dockets.dta
*/


// Before running this file, put the document and docket datasets into your working directory.

*** Data on Docuents ***

use "appeals 2021-12-31.dta", clear

*** To generate table of origins by year ***
tab year origin if year(docDate) > 2009 & (docType=="Opinion" | docType=="Rule 36") & Replaced==""

*** Table of decisions with the docket number as the record unit ***
split Appeal_Dockets, gen(temp) parse(;)
keep uniqueID year origin docType Replaced Appeal_Dockets temp*
reshape long temp, i(uniqueID) j(count)
drop if temp==""

drop if Replaced!=""
duplicates report uniqueID temp
keep if docType=="Rule 36" | docType=="Opinion"
duplicates report temp

tab year origin

use "appeals 2021-12-31.dta", clear

*** To generate tables of document type for DCT and USPTO ***

tab year docType if year(docDate) > 2009 & (docType=="Opinion" | docType=="Rule 36") & origin=="DCT" & Replaced==""
tab year docType if year(docDate) > 2009 & (docType=="Opinion" | docType=="Rule 36") & origin=="PTO" & Replaced==""

*** To generate tables of opinion precedential status for DCT and USPTO ***
tab year PrecedentialStatus if year(docDate) > 2009 & (docType=="Opinion") & origin=="DCT" & Replaced==""
tab year PrecedentialStatus if year(docDate) > 2009 & (docType=="Opinion") & origin=="PTO" & Replaced==""


*** To generate tables of dispositions for opinions and Rule 36's ***
tab year DispGeneral if year(docDate) > 2009 &  (docType=="Opinion" | docType=="Rule 36") & origin=="DCT" & Replaced==""
tab year DispGeneral if year(docDate) > 2009 &  (docType=="Opinion" | docType=="Rule 36") & origin=="PTO" & Replaced==""

*** To generate data on dissents and concurrences ***
tab year Dissent if year(docDate) > 2009 & (docType=="Opinion") & Replaced==""
tab year Concurrence if year(docDate) > 2009 & (docType=="Opinion") & Replaced==""

*** To generate tables of docket origins ***
use "2021-12-31 CAFC Dockets.dta", clear
split PACER_ID, parse(-) gen(temp)
destring temp2, replace
gen Misc_Docket = 1 if temp2<1000
tab Year_Appeal_Filed origin_PACER if Year_Appeal_Filed>2012 & Misc_Docket!=1
